PICTools Programmer's Reference
Contrast Correction

The contrast correction algorithm analyzes and/or corrects the brightness and contrast of 8 and 24-bit images.  The analysis and correction phases can be used separately or together.  The Quality setting controls how finely the image is sampled, and will also impact how sensitive the adative correction method is to local changes in contrast.

The analysis phase samples pixels in the image during the REQ_INIT phase, and calculates the background brightness and variation, and estimates the contrast and noise.  The brightness is the local average level, the noise and contrast measure are measured relative to this value.  The variance is the difference between the brightest and darkest local averages across the page.  A set of target values can be supplied for brightness, variance, and contrast; depending on the target and actual values for the image, the algorithm will suggest one of four different operations.  If the image meets the target values, the algorithm will return SCANFIX_OK_CONTRAST, indicating that no action needs to be taken.  A value of SCANFIX_BAD_CONTRAST indicates that the noise level and contrast levels were too close, and corrective action is unlikely to improve the image.  A value of SCANFIX_GLOBAL_CONTRAST or SCANFIX_ADAPTIVE_CONTRAST indicates that the image does not meet the target values, but that the given method should be helpful in correcting the deficiencies.

The parameters used for altering the image brightness are based on percentile brightness of each pixel.  Valid values for percentiles range from -1 to 101.  Values between 0 and 100 represent the given percentile brightness; a value of 90, for instance, will represent a brightness that is greater than 90 percent of sampled pixels, and less than 10 percent of sampled pixels.  A value of 0 will use the darkest sampled pixel value, while a value of 100 will use the brightest sampled pixel value. The values -1 and 101 are special values; -1 corresponds to a brightness of 0, and 101 corresponds to a brightness of 255, regardless of the contents of the image.

Example:  An image has a 90th percentile brightness of 250, and a 10th percentile brightness of 200.  Using the given minimum and maximum percentiles will produce the following results:

Using a range of 0 to 100 will maximize the utilization of brightness by linearly stretching the image so that the darkest sampled pixel will use brightness 0, and the brightest sampled pixel will use 255.  Using a narrower range of percentiles will flatten the brightness curve, which can be desirable in document images to push ink and paper colors to pure black and white respectively.  A good starting place for a document image might be a minimum of 0, and a maximum of 50.  This should eliminate much of the background noise by pushing most of the background pixels to a maximum brightness.

Contrast limits, used with the adaptive method, allow control over how much a given pixel's brightness can be modified.  In an area with very low contrast, such as blank paper, or a large block of solid color, expansion to the full range of brightness can result in undesirable amplification of image noise.  The contrast limits allow control over how much the value of a pixel in a given brightness range can change.  There are three values that control this, one for dark, midrange, and bright regions of intensity.  The simplest use is to set all of these to a single value, which will control how "intense" the algorithm will be.  A value near 0 will allow only very slight changes to the brightness of the image, while a value near 255 will allow drastic changes to the brightness.  By setting the dark, midrange, and light limits to different values, an "S" or bell shaped curve will be generated and used to determine how much change can be applied at any given level.  Since the adaptive correction attempts to maximize the local contrast, if left unchecked it will take, for example, a scanned blank page, and enhance the contrast of the noise to the full range of brightness.  Setting the contrast limits in the brightness regions where problems are occurring will limit the amount of correction applied to those pixels, and reduce the production of artifacts.

Choosing between methods can be left up to the algorithm, which will try to determine the best method to use based on the amount of background variance.  In general, the global method will provide the best results on most document images, in addition to maximizing performance.  Adaptive correction is more powerful, but it is slower and, with aggressive settings (such as high contrast limits and a high Quality value), prone to over-correct the image and produce significant artifacts.

 

 


©2022. Accusoft Corporation. All Rights Reserved.

Send Feedback